 //
//  NSDate+YCUse.m
//  YCVillageDoctor
//
//  Created by Mac on 2017/6/9.
//  Copyright © 2017年 zhangxiaoliang. All rights reserved.
//

#import "NSDate+YCUse.h"

@implementation NSDate (YCUse)

//截取时间字符串（2015年10月30日 星期五）
+(NSString *)zj_weekDayfromCreatedDate:(NSString *)strDate
{
    
    NSDate *newDate  = [NSDate dateOfStringWithFormat:YcFormatterStyleYMd WithDateString:strDate];
    NSString *newStr = [newDate stringOfDateWithFormat:YcFormatterStyleYmd];
    NSString *showStr = [newDate stringOfDateWithFormat:YcFormatterStyleYMdC];
    NSArray *arrDate = [newStr componentsSeparatedByString:@"-"];
    NSInteger year = [arrDate[0] integerValue];
    NSInteger month = [arrDate[1] integerValue];
    NSInteger day = [arrDate[2] integerValue];
    NSDateComponents *_comps = [[NSDateComponents alloc] init];
    [_comps setDay:day];
    [_comps setMonth:month];
    [_comps setYear:year];
    NSCalendar *gregorian = [[NSCalendar alloc]
                             initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDate *_date = [gregorian dateFromComponents:_comps];
    NSDateComponents *weekdayComponents =
    [gregorian components:NSCalendarUnitWeekday fromDate:_date];
    NSInteger weekday = [weekdayComponents weekday];
    
    NSString *str;
    if (weekday ==1) {
        str = @"星期日";
    }else if (weekday ==2){
        str = @"星期一";
    }else if (weekday ==3){
        str = @"星期二";
    }else if (weekday ==4){
        str = @"星期三";
    }else if (weekday ==5){
        str = @"星期四";
    }else if (weekday ==6){
        str = @"星期五";
    }else if (weekday ==7){
        str = @"星期六";
    }
    
    NSString *strdate = [NSString stringWithFormat:@"%@  %@",showStr,str];
    
    
    return strdate;
}

@end
